import { SelectionModel, TextModel } from "../models";
import SourceView from "./source_view";
import md2html from '../markdown_parse';

export class DivisionView extends SourceView {
    private _previewElement; // 双屏右侧的显示元素

    constructor (textModel: TextModel, selectionModel: SelectionModel, viewContainer: HTMLElement) {
        super(textModel, selectionModel, viewContainer);

        const previewElement: HTMLElement = document.createElement('pre');
        previewElement.setAttribute('class', 'container-pre preview');
        this._viewContainer.parentElement?.appendChild(previewElement);
        this._previewElement = previewElement;
    }

    render () {
        this._viewContainer.innerHTML = this._textModel.getSpacers() + '\n';

        setTimeout(() => {
            this.updateDomSelection()
        }, 0);

        this._previewElement.innerHTML = md2html(this._textModel.getSpacers());
    }
}

export default DivisionView